﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OnTheWay.Functions
{
    /// <summary>
    /// FunctionPanelHeaderItem.xaml 的交互逻辑
    /// </summary>
    public partial class FunctionPanelHeaderItem : ContentControl
    {
        public FunctionPanelHeaderItem()
        {
            InitializeComponent();
        }

        public bool IsSelected
        {
            get { return (bool)GetValue(IsSelectedProperty); }
            set { SetValue(IsSelectedProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsSelected.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsSelectedProperty =
            DependencyProperty.Register("IsSelected", typeof(bool),
            typeof(FunctionPanelHeaderItem), new UIPropertyMetadata(false));

        #region 事件函数

        private void ItemBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                base.RaiseEvent(new RoutedEventArgs(OnSwitchEvent, base.DataContext));
            }
            catch
            {
            }
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                base.RaiseEvent(new RoutedEventArgs(OnCloseEvent, base.DataContext));
            }
            catch
            {
            }
        }
        #endregion

        #region 路由事件

        public static readonly RoutedEvent OnCloseEvent = EventManager.RegisterRoutedEvent("OnCloseEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FunctionPanelHeaderItem));
        public static readonly RoutedEvent OnSwitchEvent = EventManager.RegisterRoutedEvent("OnSwitchEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FunctionPanelHeaderItem));

        public event RoutedEventHandler OnClose
        {
            add
            {
                base.AddHandler(OnCloseEvent, value);
            }
            remove
            {
                base.RemoveHandler(OnCloseEvent, value);
            }
        }

        public event RoutedEventHandler OnSwitch
        {
            add
            {
                base.AddHandler(OnSwitchEvent, value);
            }
            remove
            {
                base.RemoveHandler(OnSwitchEvent, value);
            }
        }

        #endregion
    }
}
